<div class="layui-card-body" >
    <link rel="stylesheet" href="/static/admin/editor/css/editormd.min.css" />
    <script src="/static/admin/editor/examples/js/jquery.min.js"></script>
    <script src="/static/admin/editor/editormd.min.js"></script>
    <style>
        .task-list-item-checkbox{
            display: inline !important;
        }
        .editormd-code-toolbar select{
            display: inline !important;
        }
        .c_time{
            float: right;
            margin: 5px;
            bottom:5px;
        }
        body{
            background: #fff
        }
        #infotitle{
            text-align: center;
        }
    </style>
    <form class="layui-form" action="{:url()}"  method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">所属分类</label>
            <div class="layui-input-block">
                <select name="category_id" lay-search>
                    <volist name="notify_category" id="vo" key="k">
                        <option value="{$k}"
                        <notempty name="info.category_id">
                            <eq name="$k" value="$info.category_id">selected="selected"</eq>
                        </notempty>
                        >{$vo} </option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="{$info.title|default=''}" class="layui-input" autocomplete="off"
                       placeholder="不要超过32个汉字">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属角色</label>
            <div class="layui-input-block">
                <volist name="group" id="vo">
                    <input type="checkbox" name="group[]" value="{$vo.id}"
                    <notempty name="info.groups">
                    <in name="vo.id" value="$info.groups">checked</in>
                </notempty>
                    lay-skin="primary" title="{$vo.title}"

                    >
                </volist>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">详情</label>
            <div class="layui-input-block">
                <div id="editormd" >
                    <textarea style="display:none;" name="info">{$info.info|raw|default=""}</textarea>
                </div>
            </div>
        </div>

        <div class="layui-form-item ">
            <label class="layui-form-label">附件信息</label>
            <div class="layui-input-block">
                <input name="file_path" id="file_path" type="text" value="{$info.file_path|default=''}"
                       class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input id="img_input" type="file"  style=" display: none;"/>
                <label for="img_input" class="layui-btn ">选择附件上传</label>
            </div>
        </div>
        <notempty name="users" >
            <div class="layui-form-item">
                <label class="layui-form-label">阅读情况</label>
                <div class="layui-input-block users">
                    <volist name="users" id="vo" key="k">
                        <eq name="vo.status" value="2">
                            <span class="reading" >{$vo.nickname}</span>
                            <else/>
                            {$vo.nickname}
                        </eq>
                    </volist>
                </div>
            </div>
            <style>
                .users{
                    max-width: 850px;
                }
                .reading{
                    color:#1E9FFF;
                }
            </style>
        </notempty>

        <input type="hidden" name="id" value="{$info.id|default=''}">
        <input type="hidden" name="info_id" value="{$info.info_id|default=''}">
    </form>
</div>

<script type="text/javascript">

    layui.use(['form', 'layer'], function () {
        var form = layui.form
            , $ = layui.$
            , laydate = layui.laydate;
        var editor = editormd("editormd", {
            placeholder:'本编辑器支持Markdown编辑，左边编写，右边预览',
            toc:true,
            tocm:true,
            tocDropdown:true,
            width:850,
            height:700,
            saveHTMLToTextarea : true,
            imageUpload:true,
            htmlDecode : true,
            //markdown: "",
            autoLoadModules : true,
            flowChart: true,             // 开启流程图支持，默认关闭
            sequenceDiagram: true,       // 开启时序/序列图支持，默认关闭,
            emoji: true,
            taskList: true,          // Enable Github Flavored Markdown task lists
            path : "/static/admin/editor/lib/" // Autoload modules mode, codemirror, marked... dependents libs path
        });
        $("#sss").click(function(){
            alert(editor.getMarkdown());
        })


        $('#file_path').click(function () {
            window.open($('#file_path').val());
        });
        $('#img_input').on('change',function () {
            var index = layer.load(1);
            var files=this.files[0];
            if(files){
                $.ajax({
                    type: "post",
                    url: "/qiniu/gettoken",
                    async: true,
                    success: function (res) {
                        if (res.code == 0) {
                            var token = res.uptoken;

                            console.log(files);
                            var fileName = res.path + files.name;
                            var downloadurl = res.downloadurl;
                            var config = {
                                retryCount: 6,
                            };
                            var putExtra = {
                                fname: "",
                                params: {},
                                mimeType: null
                            };
                            var observable = qiniu.upload(files, fileName, token, putExtra, config);
                            var subscription = observable.subscribe(
                                {
                                    next(res) {
                                        console.log(res)
                                    },
                                    error(res) {
                                        console.log(res)
                                    },
                                    complete(res) {
                                        layer.close(index);
                                        $("#file_path").val(downloadurl + '?file=' + res.key)
                                    }
                                }
                            );

                        } else {
                            console.log(res.msg)
                        }

                    }
                });
            }

        });


    });

</script>






